<template>
  <div>
    <!-- 头部 -->
    <van-nav-bar title="我的评论" left-arrow @click-left="$router.back()" />

    <!-- 内容 -->
    <div class="item" v-for="(item,index) in commentList" :key="index">
      <div class="head">
        <img src="图片路径" alt />
        <div>
          <p>发表人</p>
          <span>时间</span>
        </div>
        <span>回复</span>
      </div>
      <!-- 嵌套评论 start-->
      <hmCommentItem v-if="item.parent" :obj='item.parent' ></hmCommentItem>
      <!-- 嵌套评论 end-->
    </div>

    <!-- 底部 -->
    <hmComment :newsObj="articlObj"></hmComment>
  </div>
</template>

<script>
import { newsDetail, post_comment } from "@/apis/newsDetail";
import hmComment from "@/components/hmComment.vue";
import hmCommentItem from "@/components/hmCommentItem.vue";
export default {
  components: { hmComment, hmCommentItem },
  data() {
    return {
      articlObj: {},
      commentList: [
        {
          content: "内容一",
          parent: {
            content: "内容二",
            parent: {
              content: "我是直接评论文章的，其他都是回复",
            },
          },
        },
        {
          content: "2内容一",
          parent: {
            content: "2内容二",
          },
        },
      ],
    };
  },
  created() {
    //请求文章详情数据
    let id = this.$route.query.id;
    newsDetail(id).then((res) => {
      console.log(25, res);
      this.articlObj = res.data.data;
    });
    //请求评论列表数据
    post_comment(id).then((res) => {
      console.log(65, res);
      this.commentList = res.data.data;
    });
  },
};
</script>

<style lang="less" scoped>
.item {
  padding: 10px 0;
  border-bottom: 1px solid #ccc;
  .head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    > img {
      width: 50/360 * 100vw;
      height: 50/360 * 100vw;
      display: block;
      border-radius: 50%;
    }
    > div {
      flex: 1;
      display: flex;
      flex-direction: column;
      margin-left: 10px;
      > span {
        font-size: 12px;
        color: #999;
        line-height: 25px;
      }
    }
    > span {
      color: #999;
      font-size: 13px;
    }
  }
  .text {
    font-size: 14px;
    color: #333;
    padding: 20px 0 10px 0;
  }
}
</style>